<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改主机</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<style>
    .layui-form-item{
        width: 50%;
    }
    label{
        width:95px !important;
    }
    .layui-input-block{
        margin-left:125px;
    }
</style>
<body>
<div style="width:80%;margin:30px auto;" id="aaa">
    <form class="layui-form" action="">
        <div style="">
            <input type="hidden" class="input-text" id="id" name="id">
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>IP地址</label>
                <div class="layui-input-block">
                    <input type="text" name="ip_address" placeholder="请输入IP地址" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span> 域名</label>
                <div class="layui-input-block">
                    <input type="text" name="yu_ming"  lay-verify="required" placeholder="请输入域名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color:red">*</span>状态</label>
                <div class="layui-input-block">
                    <select lay-verify="required" lay-search id="type" name="type">
                        <option value="1">国外</option>
                        <option value="0">国内</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color:red">*</span>状态</label>
                <div class="layui-input-block">
                    <select lay-verify="required" lay-search id="pd_type" name="pd_type">
                        <option value="1">直连</option>
                        <option value="0">代理</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button style="width: 100px;" class="layui-btn" id="updYumingIp" lay-submit lay-filter="updYumingIp">确定</button>
                <button style="width: 100px;" type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/js/layui/layui.js"></script>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>

<script>
    //url 传参
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var a = decodeURI(window.location.search);
        var r = a.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if(r!=null) return  unescape(r[2]) == "null"?"":unescape(r[2]); return null;
    }
    window.onload = function(){
        var form = layui.form;
        var type = GetQueryString("type");
        $("input[name='ip_address']").val(GetQueryString("ip_address"));
        $("input[name='yu_ming']").val(GetQueryString("yu_ming"));
        $("input[name='id']").val(GetQueryString("id"));
        $('#type').find("option[value="+type+"]").attr("selected",true);
        $('#pd_type').find("option[value="+GetQueryString("pd_type")+"]").attr("selected",true);
        form.render('select');
    }
    layui.use(['form' , 'jquery' , 'upload',], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;
        //验证是不是数字
        form.verify({
            double: function(value){
                if(/^\d+$/.test(value)==false && /^\d+\.\d+$/.test(value)==false)
                {
                    return '你输入的不是数字';
                }
            },
            datetime: function (value) {
                if(value != ""){
                    if( /^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/.test(value)==false)
                    {
                        return '日期格式不正确';
                    }
                }
            }
        });

        //编辑操作
        form.on('submit(updYumingIp)',function(data){
            $.ajax({
                url: "/peizhi/updYumingIp"
                , type: "POST"
                , contentType: 'application/json'
                , data: JSON.stringify(data.field)
                , success: function (res) {
                    // console.log(res);
                    if (res.code == 0) {
                        layer.msg(res.msg);
                        setTimeout(function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            window.location.reload();
                        }, 2000);
                    } else if (res.code == 1) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg('拒绝访问');
                    }
                }
                , error: function () {
                    console.log("ajax error");
                }
            });
            return false;
        });

    });

</script>
<script>

    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#end_time',
            type: 'datetime',
        });
    });
</script>
</body>
</html>